<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodeData.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="command">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add"> 添加子部门 </el-dropdown-item>
              <el-dropdown-item command="edit" v-if="isRoot"
                >编辑部门</el-dropdown-item
              >
              <el-dropdown-item command="del" v-if="isRoot"
                >删除部门</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import { delentDepartmentListApi } from '@/api/departments'
export default {
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {}
  },
  methods: {
    command(command) {
      //点击了添加部门
      if (command == 'add') {
        this.$emit('opendialog', this.nodeData)
      }
      //点击了编辑部门
      if (command == 'edit') {
        console.log(edit)
      }
      //点击了删除部门
      if (command == 'del') {
        this.$confirm('此操作将会永久删除是否继续')
          //将部门的id传进去
          .then(() => {
            const res = delentDepartmentListApi(this.nodeData.id)
            console.log(res)
            this.$message.success('删除成功')
          })
          .catch(() => {
            console.log('点击了取消')
          })
      }
    }
  }
}
</script>
